const { execFile, spawn, exec, execSync } = require("child_process");
const { tools } = require("../utils/util");
let errCodeMsg = {
    "-4058": "模块启动文件丢失信息,请检查配置程序路径！"
}

// exports.imgPath = "https://chen88520.gitee.io/picture-cdn";
// exports.imgPath = "https://chen88520.gitee.io/electron-win11";
exports.imgPath = "";
exports.programFn = {
    openlnk(path) {
        const child = execFile(path, (error, stdout, stderr) => {
            if (error) {
                alert(errCodeMsg[error.errno]);
                throw error;
            };
            // console.log(stdout);
            // console.log(stderr);
        });
    },
    openBrowser(path = 'https://www.baidu.com/') {
        window.open(path);
    },
    undeveloped() {
        alert("暂未开发！");
    },
    openExplorer() {
        alert("暂未开发！");
    },
    execJavaGetIcon(path, name) {
        let cmd = 'java -jar GetSystemIcon.jar "' + path + '" "../../../image/picture/" "' + name + '"';
        try {
            const chilld = execSync(cmd, { cwd: __dirname + "\\tools" });
        } catch (error) {
            alert(`${tools.uint8ArrayToString(error.stderr, 'GBK')}\n请确保电脑已经正确配置java!`);
            throw error;
        }
    }
}
exports.contextMenuFn = {
    refresh(payload) {
        payload.contextMenu.style.display = '';
        setTimeout(() => payload.programBox.innerHTML = '', 186);
        setTimeout(payload.loadDesktop, 300);
        // location.reload();
    }
}